<?php

/* -----------------------------------------------------------------
 * 	$Id: compatibility.php 420 2013-06-19 18:04:39Z akausch $
 * 	Copyright (c) 2011-2021 commerce:SEO by Webdesign Erfurt
 * 	http://www.commerce-seo.de
 * ------------------------------------------------------------------
 * 	based on:
 * 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
 * 	(c) 2002-2003 osCommerce - www.oscommerce.com
 * 	(c) 2003     nextcommerce - www.nextcommerce.org
 * 	(c) 2005     xt:Commerce - www.xt-commerce.com
 * 	Released under the GNU General Public License
 * --------------------------------------------------------------- */

defined('_VALID_XTC') or die('Direct Access to this location is not allowed.');

////
// Recursively handle magic_quotes_gpc turned off.
// This is due to the possibility of have an array in
// $HTTP_xxx_VARS
// Ie, products attributes
function do_magic_quotes_gpc(&$ar) {
    if (!is_array($ar))
        return;

    while (list($key, $value) = each($ar)) {
        if (is_array($value)) {
            do_magic_quotes_gpc($value);
        } else {
            $ar[$key] = addslashes($value);
        }
    }
}

// $HTTP_xxx_VARS are always set on php4
if (!is_array($_GET))
    $_GET = array();
if (!is_array($_POST))
    $_POST = array();
if (!is_array($_COOKIE))
    $_COOKIE = array();

// handle magic_quotes_gpc turned off.
if (!get_magic_quotes_gpc()) {
    do_magic_quotes_gpc($_GET);
    do_magic_quotes_gpc($_POST);
    do_magic_quotes_gpc($_COOKIE);
}

if (!function_exists('is_numeric')) {

    function is_numeric($param) {
        return preg_match("/^[0-9]{1,50}.?[0-9]{0,50}$/", $param);
    }

}

if (!function_exists('is_uploaded_file')) {

    function is_uploaded_file($filename) {
        if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
            $tmp_file = dirname(tempnam('', ''));
        }

        if (strchr($tmp_file, '/')) {
            if (substr($tmp_file, -1) != '/')
                $tmp_file .= '/';
        } elseif (strchr($tmp_file, '\\')) {
            if (substr($tmp_file, -1) != '\\')
                $tmp_file .= '\\';
        }

        return file_exists($tmp_file . basename($filename));
    }

}

if (!function_exists('move_uploaded_file')) {

    function move_uploaded_file($file, $target) {
        return copy($file, $target);
    }

}

if (!function_exists('checkdnsrr')) {

    function checkdnsrr($host, $type) {
        if (xtc_not_null($host) && xtc_not_null($type)) {
            @exec("nslookup -type=$type $host", $output);
            while (list($k, $line) = each($output)) {
                if (preg_match("/^$host/i", $line)) {
                    return true;
                }
            }
        }
        return false;
    }

}
